package com.qfedu.java1234.controller;

import com.qfedu.java1234.entity.vo.ResultVO;
import com.qfedu.java1234.service.UserService;
import com.qfedu.java1234.util.JwtUtils;
import com.qfedu.java1234.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName TestController
 * @Author ykx
 * @Date 2024/4/20 23:25
 * @Version 1.0
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    public UserService userService;

    @RequestMapping("/user/list")
//    @PreAuthorize("hasRole('ROLE_admin')")
    @PreAuthorize("hasAnyAuthority('system:user:list')")
    public ResultVO getUserList(@RequestHeader(required = false) String token) {
        if (StringUtil.isNotEmpty(token)) {
            return ResultVO.success(userService.list());
        }
        return ResultVO.failed(401, "没有权限访问");
    }

    @RequestMapping("/login")
    public ResultVO login() {
        String java1234 = JwtUtils.genJwtToken("java1234");
        return ResultVO.success(java1234);
    }

}
